package com.xdty.fastInput.utils;

import java.awt.*;
import java.awt.event.KeyEvent;

/**
 * @Author: BaiShiSheng
 * @Create: 2024/12/12/10:13
 */
public class RobotUtil {
    public static Robot robot;

    static {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    public static void autoInput(String content) {
        System.out.println("开始拼写："+content);
        robot.delay(300);
        for (char character : content.toCharArray()) {
            int keyCode = KeyEvent.getExtendedKeyCodeForChar(character);
            boolean isUpperCase = Character.isUpperCase(character);

            if (isUpperCase) {
                robot.keyPress(KeyEvent.VK_SHIFT);
            }

            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);

            if (isUpperCase) {
                robot.keyRelease(KeyEvent.VK_SHIFT);
            }

            // 添加一个小延迟，确保字符输入的顺序正确
            robot.delay(50);
        }
    }
}
